<?php use_javascript(plugin_web_path('orangehrmTLUPimPlugin', 'js/viewProfileDocumentTypesSuccess')); ?>

<?php

function getSortClass($column, $sortField, $sortOrder)
{

    if (isset($sortField) && isset($sortOrder) && $column == $sortField) {
        $class = ' headerSort';
        $class .= ($sortOrder == 'ASC') ? 'Up' : 'Down';
        return $class;
    }

    return '';

}

?>

<?php echo isset($templateMessage) ? templateMessage($templateMessage) : ''; ?>

<div id="saveFormDiv" class="box">

    <div class="head">
        <h1 id="saveFormHeading"><?php echo __('Add Profile Document Type'); ?></h1>
    </div>

    <div class="inner">

        <form name="frmSave" id="frmSave" method="post"
              action="<?php echo url_for('tlupim/viewProfileDocumentTypes'); ?>">

            <?php echo $form['_csrf_token']; ?>
            <?php echo $form['id']->render(); ?>

            <fieldset>

                <ol>
                    <li>
                        <?php echo $form['code']->renderLabel(__('Profile Document Type Code') . ' <em>*</em>'); ?>
                        <?php echo $form['code']->render(array("maxlength" => 10)); ?>
                    </li>

                    <li>
                        <?php echo $form['name']->renderLabel(__('Profile Document Type Name') . ' <em>*</em>'); ?>
                        <?php echo $form['name']->render(array("maxlength" => 100)); ?>
                    </li>

                    <li class="largeTextBox">
                        <?php echo $form['description']->renderLabel(__('Profile Document Type Description')); ?>
                        <?php echo $form['description']->render(array("maxlength" => 600)); ?>
                    </li>

                    <li class="required">
                        <em>*</em> <?php echo __(CommonMessages::REQUIRED_FIELD); ?>
                    </li>

                </ol>

                <p>
                    <input type="button" class="" name="btnSave" id="btnSave" value="<?php echo __('Save'); ?>"/>
                    <input type="button" id="btnCancel" class="reset" value="<?php echo __('Cancel'); ?>"/>
                </p>

            </fieldset>

        </form>

    </div>

</div> <!-- saveFormDiv -->

<!-- Listi view -->

<div id="recordsListDiv" class="box miniList">

    <div class="head">
        <h1><?php echo __('Profile Document Types'); ?></h1>
    </div>

    <div class="inner">

        <?php include_partial('global/flash_messages'); ?>

        <form name="frmList" id="frmList" method="post"
              action="<?php echo url_for('tlupim/deleteProfileDocumentTypes'); ?>">

            <fieldset>

                <p id="listActions">
                    <input type="button" class="addbutton" id="btnAdd" value="<?php echo __('Add'); ?>"/>
                    <!--                    <input type="button" class="delete" id="btnDel" value="-->
                    <?php //echo __('Delete'); ?><!--"/>-->
                    <input type="button" class="delete" id="btnDel" value="<?php echo __('Delete'); ?>"
                           data-toggle="modal" data-target="#deleteConfModal"/>
                </p>

            </fieldset>

            <table class="table hover" id="recordsListTable">
                <thead>
                <tr>
                    <th class="check" style="width:2%"><input type="checkbox" id="checkAll" class="checkbox"/></th>
                    <th class="fieldCode header<?php echo getSortClass('code', $sortField, $sortOrder); ?>"
                        style="width:49%">
                        <?php echo $sorter->sortLink('code', __('Profile Document Type Code'), '@profiledocumenttype_list', ESC_RAW); ?>
                    </th>
                    <th class="fieldName header<?php echo getSortClass('name', $sortField, $sortOrder); ?>"
                        style="width:49%">
                        <?php echo $sorter->sortLink('name', __('Profile Document Type Name'), '@profiledocumenttype_list', ESC_RAW); ?>
                    </th>
                </tr>
                </thead>
                <tbody>

                <?php
                $i = 0;
                foreach ($records as $record):
                    ?>
                    <tr class="<?php echo ($i & 1) ? 'even' : 'odd' ?>">
                        <td class="check">
                            <input type="checkbox" class="checkbox" name="chkListRecord[]"
                                   value="<?php echo $record->getId(); ?>"/>
                        </td>
                        <td class="tdCode tdValue">
                            <a href="#"><?php echo __($record->getCode()); ?></a>
                        </td>
                        <td class="tdName tdValue">
                            <?php echo __($record->getName()); ?>
                        </td>
                        <td class="tdDescription tdValue" style="display: none;">
                            <?php echo __($record->getDescription()); ?>
                        </td>
                    </tr>

                    <?php
                    $i++;
                endforeach;
                ?>

                <?php if (count($records) == 0) : ?>
                    <tr>
                        <td>
                            <?php echo __(TopLevelMessages::NO_RECORDS_FOUND); ?>
                        </td>
                    </tr>
                <?php endif; ?>

                </tbody>
            </table>

        </form>

    </div>

</div> <!-- recordsListDiv -->

<?php include_partial('global/delete_confirmation'); ?>

<script type="text/javascript">
    //<![CDATA[

    var recordsCount = <?php echo count($records);?>;

    var recordKeyId = "profileDocumentType_id";

    var saveFormFieldIds = new Array();
    saveFormFieldIds[0] = "profileDocumentType_code";
    saveFormFieldIds[1] = "profileDocumentType_name";
    saveFormFieldIds[2] = "profileDocumentType_description";

    var lang_exceed10Chars = '<?php echo __(ValidationMessages::TEXT_LENGTH_EXCEEDS, array('%amount%' => 10)); ?>';
    var lang_exceed100Chars = '<?php echo __(ValidationMessages::TEXT_LENGTH_EXCEEDS, array('%amount%' => 100)); ?>';
    var lang_exceed600Chars = '<?php echo __(ValidationMessages::TEXT_LENGTH_EXCEEDS, array('%amount%' => 600)); ?>';

    var urlForExistingCodeCheck = '<?php echo url_for('tlupim/checkProfileDocumentTypeCodeExistence'); ?>';

    var lang_addFormHeading = "<?php echo __('Add Profile Document Type'); ?>";
    var lang_editFormHeading = "<?php echo __('Edit Profile Document Type'); ?>";

    var lang_codeIsRequired = '<?php echo __(ValidationMessages::REQUIRED); ?>';
    var lang_codeExists = "<?php echo __('Code exists'); ?>";
    var lang_nameIsRequired = '<?php echo __(ValidationMessages::REQUIRED); ?>';
    var lang_descriptionIsRequired = '<?php echo __(ValidationMessages::REQUIRED); ?>';

    //]]>
</script>